package eiisan.constant.enums.task;

import eiisan.constant.annotations.decoration.EnumCheckable;
import eiisan.constant.enums.IEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 任务状态枚举
 **/
@EnumCheckable
@AllArgsConstructor
public enum StatusEnum implements IEnum<Byte> {

    /**
     * 1:活跃中
     */
    ACTIVE((byte) 1, "活跃中"),
    /**
     * 2:不活跃
     */
    PAUSED((byte) 2, "不活跃");

    private static final Map<Byte, StatusEnum> enumMap;
    /**
     * 所有值
     */
    @Getter
    private static List<Byte> vals;
    /**
     * 所有描述
     */
    @Getter
    private static List<String> descs;

    static {
        vals = Arrays.asList(StatusEnum.values()).stream().map(StatusEnum::getVal).collect(Collectors.collectingAndThen(Collectors.toList(), Collections::unmodifiableList));
        descs = Arrays.asList(StatusEnum.values()).stream().map(StatusEnum::getDesc).collect(Collectors.collectingAndThen(Collectors.toList(), Collections::unmodifiableList));
        enumMap = new HashMap<>();
        for (StatusEnum iter : StatusEnum.values()) {
            enumMap.put(iter.val, iter);
        }
    }

    /**
     * 值
     */
    @Getter
    private Byte val;

    /**
     * 描述
     */
    @Getter
    private String desc;

    public static StatusEnum of(Byte value) {
        return enumMap.get(value);
    }

}
